package com.fuego.creditsystemresourse.controller;

//
//import cn.hutool.core.io.FileUtil;
//import org.example.dto.Result;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.File;
//import java.io.IOException;
//import java.util.UUID;
//
//@RestController
//@RequestMapping("/upload")
//public class ResourceUploadController {
//
//    private String uploadBaseDir="C:/Users/Wangy/Desktop/syt_credict_system_backend/credit-system-resource/src/main/resources";
//
//    @PostMapping("/user")
//    public Result uploadUserImage(@RequestParam("file") MultipartFile file) throws IOException {
//        // 确定上传目录
//        String userImageDir = uploadBaseDir + "/static/images/user/";
//
//        // 确保目录存在
//        File dir = new File(userImageDir);
//        if (!dir.exists()) {
//            dir.mkdirs();
//        }
//
//        // 生成唯一文件名
//        String originalFilename = file.getOriginalFilename();
//        String extension = originalFilename.substring(originalFilename.lastIndexOf("."));
//        String fileName = UUID.randomUUID().toString() + extension;
//
//        // 保存文件
//        File dest = new File(userImageDir + fileName);
//        file.transferTo(dest);
//
//        // 返回相对路径
//        String relativePath = "/images/user/" + fileName;
//        System.out.println(userImageDir + fileName);
//        return Result.ok(relativePath);
//    }
//}